using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace TidhiGanitam.DataModel
{
    public class BhuktiRoutineItem
    {
        private int m_Year;
        DateTime m_Date;
        private int m_SNo;
        DinamuRoutineItem m_DinamuRoutine;
        RaviRoutineItem m_RaviRoutine;
        Rasi m_Bhukti;
        Rasi m_PunarBukti;

        public int Bhagam
        {
            get { return m_SNo; }
        }

        public DateTime Date
        {
            get { return m_Date; }
        }
        public Rasi Bhukti
        {
            get
            {return m_Bhukti;}
        }
        public Rasi PunarBhukti
        {
            get
            { return m_PunarBukti; }
            set
            { m_PunarBukti = value; }
        }
        public BhuktiRoutineItem(int SNo, int Year, DateTime Date, DinamuRoutineItem CurrentDinamuRoutine,
                RaviRoutineItem RaviRoutine)
        {
            m_SNo = SNo;
            m_Year = Year;
            m_Date = Date;
            m_DinamuRoutine = CurrentDinamuRoutine;
            m_RaviRoutine = RaviRoutine;
            m_Bhukti = new Rasi();
            m_PunarBukti = new Rasi();
        }
        public void Calculate(BhuktiRoutineItem PreviousBhuktiItem, ArkahaRoutineItem CurrentArkaha)
        {
            //Get the ravi value at noon
            Rasi MadhyamaRaviNoonValue = new Rasi(m_RaviRoutine.MadyamaRavi);
            Rasi RaviGati = new Rasi(m_RaviRoutine.Gati);

            //Now we need to find the value of ravi at Suryodayamu
            //Multiply Dinardhamu * Gati = we get ravi Advancement 
            //subtract this from noon value. we get ravi value at suryodayamu

            Rasi RaviAdvancementAfterSuryodayamu = new Rasi(m_DinamuRoutine.Dinardhamu * RaviGati);
            Rasi MadyamaRaviSuryodayamuValue = new Rasi(MadhyamaRaviNoonValue - RaviAdvancementAfterSuryodayamu);
            Rasi CurrentRasiSpan = (Rasi)Constants.BhuktiPramanamulu[(int)MadyamaRaviSuryodayamuValue.Rasulu];
            MadyamaRaviSuryodayamuValue = new Rasi(0, MadyamaRaviSuryodayamuValue.Bhagalu,
                                                    MadyamaRaviSuryodayamuValue.Liptalu,
                                                    MadyamaRaviSuryodayamuValue.Paralu);
            m_Bhukti = new Rasi(CurrentRasiSpan * MadyamaRaviSuryodayamuValue / 30);
            //if previous day has punrbhukti we need not check for today
            if (PreviousBhuktiItem.PunarBhukti == new Rasi())
            {
                Rasi RaviAdvancement = new Rasi(MadyamaRaviSuryodayamuValue + m_RaviRoutine.Gati);
                if (RaviAdvancement.Rasulu != 0) //Ravi entered new rasi in this day
                {
                    m_PunarBukti = new Rasi(CurrentRasiSpan);
                }
            }
        }
        public string GetBhuktiDetailsString()
        {
            string retString = string.Empty;
            if (m_PunarBukti > new Rasi())
            {
                retString = string.Format("{0}.{1} {2}.{3}",
                "Bhukti",
                m_Bhukti.DisplayFormat(Enums.DisplayFormat.LVP),
                "Pu_Bhu",
                m_PunarBukti.DisplayFormat(Enums.DisplayFormat.LV));
            }
            else
            {
                retString = string.Format("{0}.{1}",
                "Bhukti",
                m_Bhukti.DisplayFormat(Enums.DisplayFormat.LVP));
            }
            return retString;  
        }
    }
}
